import request from './request'

const userApi = {
  // 用户登录
  login: (data) => {
    return request({
      url: '/user/login',
      method: 'post',
      data
    })
  },

  // 用户注册
  register: (data) => {
    return request({
      url: '/user/register',
      method: 'post',
      data
    })
  },

  // 获取当前用户信息
  getCurrentUser: () => {
    return request({
      url: '/user/current',
      method: 'get'
    })
  },

  // 更新当前用户信息
  updateCurrentUser: (data) => {
    return request({
      url: '/user/current',
      method: 'put',
      data
    })
  },

  // 根据ID获取用户信息
  getUserById: (id) => {
    return request({
      url: `/user/${id}`,
      method: 'get'
    })
  },

  // 上传用户头像
  uploadAvatar: (file) => {
    const formData = new FormData()
    formData.append('file', file)
    
    return request({
      url: '/file/upload/avatar',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
}

export default userApi 